package Boundry;


import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Image;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.EmptyBorder;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.awt.Label;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.SystemColor;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JPasswordField;

import Boundry.GenericTools.InputPanel;
import Controllers.GlobalData;
import Controllers.GuiManager;
import Controllers.UsersManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.MatteBorder;

public class LoginPanel extends InputPanel {

	/**
	 *  TODO we need to set the visibility of label error when text box was pressed.
	 */
	private static final long serialVersionUID = 1L;
	private JTextField txtUserName;
	private JPasswordField UserPassField;
	public JButton btnLog;
	public JButton btnClear;
	private JLabel lblIncorrectUserName;
	private JLabel lblIncorrectPassword;
	
	private char userType ;    //TODO initialize the type by the user number


	 public String getUserPassword() {
			return new String(UserPassField.getPassword());
		}
	
	 public String getUserName() {
		return txtUserName.getText();
	    }
	
	 
	 public void clearPasswordField(){
		 
		 UserPassField.setText("");
	 }
	 
	 public void clearNameField(){
		 
		 txtUserName.setText("");

	 }
	 
	 public void showNameError(){
		
		 lblIncorrectUserName.setVisible(true);
	 }
	 
     public void showPasswordError(){
		 
    	 lblIncorrectPassword.setVisible(true);
		 
	 }
     public void disappearNameError(){
 		
		 lblIncorrectUserName.setVisible(false);
	 }
	 
     public void disappearshowPasswordError(){
		 
    	 lblIncorrectPassword.setVisible(false);
		 
	 }
	 
	 
	
 public LoginPanel() 
 {
 	mainPanel.setLayout(null);
 	
 	JPanel panelLogin = new JPanel();
 	panelLogin.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 153, 204)));
 	panelLogin.setBounds(263, 11, 380, 320);
 	mainPanel.add(panelLogin);
 	panelLogin.setLayout(null);
 	
 	JLabel lblLogin = new JLabel("Login");
 	lblLogin.setFont(new Font("Tahoma", Font.BOLD, 16));
 	lblLogin.setBounds(162, 58, 79, 25);
 	panelLogin.add(lblLogin);
 	
 	JLabel lblNewLabel = new JLabel("User Name:");
 	lblNewLabel.setBounds(69, 130, 75, 14);
 	panelLogin.add(lblNewLabel);
 	
 	JLabel lblNewLabel_1 = new JLabel("User Password:");
 	lblNewLabel_1.setBounds(48, 186, 96, 14);
 	panelLogin.add(lblNewLabel_1);
 	
 	txtUserName = new JTextField();
 	txtUserName.setBounds(143, 125, 144, 25);
 	panelLogin.add(txtUserName);
 	txtUserName.setColumns(10);
 	
 	btnLog=new JButton();
 	btnLog.setIcon(new ImageIcon(LoginPanel.class.getResource("/ICONS/10_device_access_not_secure.png")));
 	btnLog.setBounds(284, 265, 86, 45);
 	panelLogin.add(btnLog);

 	
 	UserPassField = new JPasswordField();
 	UserPassField.setBounds(143, 181, 144, 25);
 	panelLogin.add(UserPassField);
 	
 	lblIncorrectUserName = new JLabel("Incorrect User Name");
 	lblIncorrectUserName.setVisible(false);
 	lblIncorrectUserName.setForeground(new Color(255, 0, 0));
 	lblIncorrectUserName.setBounds(143, 105, 130, 14);
 	panelLogin.add(lblIncorrectUserName);
 	
 	lblIncorrectPassword = new JLabel("Incorrect Password");
 	lblIncorrectPassword.setVisible(false);
 	lblIncorrectPassword.setForeground(new Color(255, 0, 0));
 	lblIncorrectPassword.setBounds(143, 165, 118, 14);
  	panelLogin.add(lblIncorrectPassword);
  	
  	JLabel label = new JLabel("");
  	label.setIcon(new ImageIcon(LoginPanel.class.getResource("/ICONS/10_device_access_accounts.png")));
  	label.setBounds(297, 169, 32, 45);
  	panelLogin.add(label);
  	
  	JLabel lblLogin_1 = new JLabel("Login");
  	lblLogin_1.setBounds(312, 249, 46, 14);
  	panelLogin.add(lblLogin_1);
  	
  	JLabel lblNewLabel_2 = new JLabel("");
  	lblNewLabel_2.setIcon(new ImageIcon(LoginPanel.class.getResource("/ICONS/6_social_add_person.png")));
  	lblNewLabel_2.setBounds(297, 117, 46, 41);
  	panelLogin.add(lblNewLabel_2);
  	
  	btnClear = new JButton("");
  	btnClear.setIcon(new ImageIcon(LoginPanel.class.getResource("/ICONS/5_content_backspace.png")));
  	btnClear.setBounds(10, 265, 86, 45);
  	panelLogin.add(btnClear);
  	
  	JLabel lblClear = new JLabel("Clear");
  	lblClear.setBounds(38, 249, 46, 14);
  	panelLogin.add(lblClear);
  	
  	JLabel lblLogo = new JLabel("");
  	lblLogo.setBounds(107, 2, 180, 56);
  	panelLogin.add(lblLogo);
  	lblLogo.setIcon(new ImageIcon(LoginPanel.class.getResource("/ICONS/ORT_Braude_logo.jpg")));
  	
  	buttonPanel.setVisible(false);
  	
  	this.revalidate();
	this.repaint();

	
  }
 
 
 
 
 
 public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JFrame muf = new JFrame();
					muf.setSize(GlobalData.FrameWidth,GlobalData.FrameHeight);
					LoginPanel loginPane = new LoginPanel();
					muf.setVisible(true);
					muf.getContentPane().add(loginPane);
					
					
					
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
}       
